package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.Option;
import com.itheima.mapper.OptionMapper;
import com.itheima.service.db.OptionService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class OptionServiceImpl implements OptionService {
    @Autowired
    OptionMapper optionMapper;

    @Override
    public List<Option> findByQuestionId(Long id) {
        LambdaQueryWrapper<Option> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Option::getQuestionId, id);
        return optionMapper.selectList(lqw);
    }

    @Override
    public Integer getUserScore(List<Long> questions, List<Long> options) {
        QueryWrapper<Option> qw = new QueryWrapper<>();
        qw.in("question_id", questions).in("id", options).select("sum(score) as score");
        Option option = optionMapper.selectOne(qw);
        return option.getScore();
    }
}
